#!/usr/bin/env python
# -*- coding: UTF-8 -*-



import sys
import re

def formatUrl(url):
    if url.startswith("http://"):
        url=url[7:]
    if url.endswith("/"):
        url=url[:-1]
    return url

def dslash(url):
    if url.endswith("/"):
        url=url[:-1]
    return url

conversionList={}
url2id={}  #cid,sid, 配置表中ID 对应 url
#页面配置
with open(sys.argv[1]) as f:
    for line in f:
        t = line.strip().split("\001")
        if len(t) == 4:
            cpid,cid,sid,page = t #aid 表中自动给的id

            for url in page.split("!_@_!",-1):
                cid=cid.strip()
                sid=sid.strip()
                url=formatUrl(url.strip())
                if not url2id.has_key(cid+sid):
                    url2id[cid+sid]=[]
                url2id[cid+sid].append(url)

#事件配置
eventid={}
with open(sys.argv[2]) as f:
    for line in f:
        t = line.strip().split("\001")
        if len(t) == 4:
            cid,sid,eid,times = t #aid 表中自动给的id
            cid=cid.strip()
            sid=sid.strip()
            eid=eid.strip()
            if not eventid.has_key(cid+sid):
                eventid[cid+sid]=[]
            eventid[cid+sid].append(eid)

#时长配置
time_dict={}
with open(sys.argv[3]) as f:
    for line in f:
        t = line.strip().split("\001")
        if len(t) == 4:
            cid,sid,ctid,time = t #aid 表中自动给的id

            cid=cid.strip()
            sid=sid.strip()
            # time_dict.setdefault(cid+sid,time.strip())
            # if not time_dict.has_key():
            #     time_dict[url]={}
            time_dict[cid+sid]=int(time.strip())


def getconversion(cid,sid,duration,ep,event):
    count=0
    k=cid.strip()+sid.strip()
    if k in url2id:
        ep=formatUrl(ep.strip())
        for url in url2id[k]:
            try:
                m=re.match(url+"$",ep)
                if m:
                    count = count +1
            except:
                pass

    if k in eventid and event.strip() in eventid[k]:
        count = count +1
    if k in time_dict and time_dict[k] <= int(round(float(duration))):
        count = count +1

    return count




for line in sys.stdin:
    t=line.strip().split("\t")
    if len(t)==9:

        cid,sid,session,nasid,duration,exit_flag,ip,ep,eventids=t
        if ep =="" or not ep.startswith("http:"):
            continue
        ep=dslash(ep)
        count=getconversion(cid,sid,duration,ep,eventids)
        print cid+"\t"+sid+"\t"+session+"\t"+nasid+"\t"+duration+"\t"+exit_flag+"\t"+ip+"\t"+ep+"\t"+str(count)

